/*
*    Phantom Test Driver v2.0 GUI Automation Software
*    Copyright (C) 2009  John C. Van Arsdall (john@phantomtest.com)
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License along
*    with this program; if not, write to the Free Software Foundation, Inc.,
*    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
/*
 * DeclPanelBase.java
 *
 * Created on August 24, 2007, 10:29 AM
 */

package ptd_decl_objects;

import ptd.Main;

/**
 *
 * @author  John
 */
public class DeclPanelBase extends javax.swing.JPanel {
    
    DeclBase myBase;
    
    /** Creates new form DeclPanelBase */
    public DeclPanelBase() {
        initComponents();
        DeclNameLabel.setText("Name");
        DeclClassLabel.setText("Class");
        DeclTagLabel.setText("Tag");
        ApplyButton.setText("Apply");
        ResetButton.setText("Reset");
        
        ApplyButton.setToolTipText("Applies the changes");
        ResetButton.setToolTipText("Resets the fields to the original values");
        
        DeclClass.setToolTipText("The Class of the window");
        DeclName.setToolTipText("The Name of the window");
        DeclTag.setToolTipText("The Tag of the window");
        ApplyButton.setEnabled(false);
        ResetButton.setEnabled(false);
    }
    
    public void setProps(DeclBase inProps){
        myBase = inProps;
        DeclName.setText(inProps.myName);
        DeclClass.setText(inProps.myClass);
        DeclTag.setText(inProps.myTag);
        
        DeclNameLabel.setVisible(true);
        DeclClassLabel.setVisible(true);
        DeclTagLabel.setVisible(true);
        if(inProps.myType == DeclBase.TYPE_FILE){
            DeclName.setEditable(false);
            DeclName.setVisible(true);
            DeclClass.setVisible(false);
            DeclTag.setVisible(false);
            DeclClassLabel.setVisible(false);
            DeclTagLabel.setVisible(false);
            ApplyButton.setEnabled(false);
            ResetButton.setEnabled(false);

        }else if(inProps.myType == DeclBase.TYPE_TOP){
            DeclName.setVisible(false);
            DeclClass.setVisible(false);
            DeclTag.setVisible(false);
            DeclNameLabel.setVisible(false); 
            DeclClassLabel.setVisible(false);
            DeclTagLabel.setVisible(false);
            ApplyButton.setEnabled(false);
            ResetButton.setEnabled(false);
        }else{
            DeclName.setEditable(true);
            DeclName.setVisible(true);
            DeclClass.setEditable(true);
            DeclClass.setVisible(true);
            DeclTag.setEditable(true);
            DeclTag.setVisible(true);
            ApplyButton.setEnabled(true);
            ResetButton.setEnabled(true);
            if(inProps.isUseable == false){
                DeclName.setEditable(false);
                DeclClass.setEditable(false);
                DeclTag.setEditable(false);
                ApplyButton.setEnabled(false);
                ResetButton.setEnabled(false);
            }
        }
    }
    
    public DeclBase getProps(){
        if(myBase == null){
            return null;
        }
        
        String sName = DeclName.getText();
        String sClass = DeclClass.getText();
        String sTag = DeclTag.getText();
        
        if(sName.compareTo(myBase.myName) != 0){
            myBase.bModifiedFlag = true;
        }
        if(sClass.compareTo(myBase.myClass) != 0){
            myBase.bModifiedFlag = true;
        }
        if(sTag.compareTo(myBase.myTag) != 0){
            myBase.bModifiedFlag = true;
        }        
        
        myBase.myName = sName;
        myBase.myClass = sClass;
        myBase.myTag = sTag;
        
        return myBase;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        DeclNameLabel = new javax.swing.JLabel();
        DeclTagLabel = new javax.swing.JLabel();
        DeclClassLabel = new javax.swing.JLabel();
        DeclName = new javax.swing.JTextField();
        DeclTag = new javax.swing.JTextField();
        DeclClass = new javax.swing.JTextField();
        FillerLabel = new javax.swing.JLabel();
        ApplyButton = new javax.swing.JButton();
        ResetButton = new javax.swing.JButton();

        setLayout(new java.awt.GridBagLayout());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(DeclNameLabel, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(DeclTagLabel, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(DeclClassLabel, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(DeclName, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(DeclTag, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(DeclClass, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        add(FillerLabel, gridBagConstraints);

        ApplyButton.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        ApplyButton.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        ApplyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ApplyButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        add(ApplyButton, gridBagConstraints);

        ResetButton.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        ResetButton.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        ResetButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ResetButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        add(ResetButton, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

private void ApplyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ApplyButtonActionPerformed
    Main.getMainFrame().ApplyDecls();
}//GEN-LAST:event_ApplyButtonActionPerformed

private void ResetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ResetButtonActionPerformed
    setProps(myBase);
}//GEN-LAST:event_ResetButtonActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ApplyButton;
    private javax.swing.JTextField DeclClass;
    private javax.swing.JLabel DeclClassLabel;
    private javax.swing.JTextField DeclName;
    private javax.swing.JLabel DeclNameLabel;
    private javax.swing.JTextField DeclTag;
    private javax.swing.JLabel DeclTagLabel;
    private javax.swing.JLabel FillerLabel;
    private javax.swing.JButton ResetButton;
    // End of variables declaration//GEN-END:variables
    
}
